package edu.fudan.cse.medlab.event.filter;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Hashtable;

public class Settings {
	public String host; 
	public String dbname;
	public String username;
	public String password; 
	public String folder;
	public int  sitecount,updatefrequent;
	public String proxyhost;
	public String proxyport;
	public String proxyusername;
	public String proxypassword;
	public Settings() {
		try{
			Hashtable<String,String> ht = new Hashtable();
			BufferedReader in = new BufferedReader(new FileReader("eventConfig.txt"));
			String s,key,value;
			edu.fudan.cse.medlab.event.extraction.DB.addLog("reading configuration");
			while((s=in.readLine())!=null){
				if(s.contains("=")){
					key = s.substring(0,s.indexOf("="));
					value = s.substring(s.indexOf("=")+1);
					key = key.trim();
					value = value.trim();
					ht.put(key, value);
				}
			}
			in = new BufferedReader(new FileReader("userConfig.txt"));
			while((s=in.readLine())!=null){
				if(s.contains("=")){
					key = s.substring(0,s.indexOf("="));
					value = s.substring(s.indexOf("=")+1);
					key = key.trim();
					value = value.trim();
					ht.put(key, value);
				}
			}
			host = ht.get("HOST");
			host.trim();
			dbname = ht.get("DBNAME");
			dbname.trim();
			username = ht.get("USERNAME");
			username.trim();
			password = ht.get("PASSWORD");
			password.trim();
			folder = ht.get("folder");
			folder.trim();
			if(!folder.endsWith("\\"))
				folder = folder+"\\";
			sitecount = Integer.parseInt(ht.get("sitecount"));
			updatefrequent = Integer.parseInt(ht.get("updatefrequent"));
			proxyhost = ht.get("PROXYHOST");
			proxyport = ht.get("PROXYPORT");
			proxyusername = ht.get("PROXYUSERNAME");
			proxypassword = ht.get("PRXOYPASSWORD");
			
		}
		catch(Exception e){
			e.printStackTrace();
			edu.fudan.cse.medlab.event.extraction.DB.addLog("fail in reading setting file");
		}
	}

}
